package shaders;

import helpers.ColorHelper;

import java.awt.Color;
import java.awt.image.BufferedImage;

import javax.vecmath.Vector3d;

import essential.Ray;


public class WaterShader extends Shader {

	
	public WaterShader(){
		  per.persistence = 0.7;
		  per.n = 1;
		  
      	  spec = 1;
      	  diff = 0;
      	  refr = 0.2;
      	  refl = 0.05;
      	  
      	int width = 1000;
		int height = 1000;
		textureImage = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
      	  
	}
			
	  
	public Color calculateColor(Ray r, Vector3d sp) {
		// TODO Auto-generated method stub
		return null;
	}
	

	@Override
	public Shader copy() {
		Shader s = new MatteShader();
		this.copyFromTo(this,s);
		return s;
	}




	@Override
	public Color calculateColor2d(int x, int y) {

		if(!textureIsSet){
			createTexture();
			textureIsSet = true;
		}
		
		
		return new Color(textureImage.getRGB(x, y));
	}




	@Override
	public Color calculateColor3d(Ray r, Vector3d sp) {

		return Color.red;
	}

	@Override
	public double fBump(double x, double y, double z) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Color textureColor(double x, double y) {
		
		double amount = per.perlinNoise(x, y)
			+ 0.5 * per.perlinNoise(2 * x, 2 * y)
			+ 0.25 * per.perlinNoise(4 * x, 4 * y)
			+ 0.125 * per.perlinNoise(8 * x, 8 * y)
			+ 0.0625 * per.perlinNoise(16 * x, 16 * y)
			+ 0.0312 * per.perlinNoise(32 * x, 32 * y);
		
		
		return  ColorHelper.sumColor(
			ColorHelper.mulColor(color, 0.4*amount),
			ColorHelper.mulColor(gradientColor, 0.4-amount)
		);		
		
	}
	
}
